home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-12-06 | 4.8 KB | 229 lines | [TEXT/PJMM] |
- program CalcErr;
-
- {}
- {}
- { This program tests the mean accuracy of the sine, cosine and tangens tables. Use the Run... }
- { Menu to select the correct table. This program calculates the mean error mentioned in the }
- { Appendix B of the Fast Performance Trigs documentation }
- {}
- { © 1992 by Christian Franz }
- {}
- {}
- { To generate only summary output, set the visual compiler directive to FALSE }
-
-
- uses
- FastPerfTrigs;
-
- var
- i: integer;
- x, y: integer;
- a: real;
- TheErr: OSErr;
- count: Integer;
- Delta: real;
- maxdelta: real;
- Sumdelta: real;
- deltapos: real;
- t1, t2: real;
- Trect: Rect;
-
- const
- Tries = 20;
- treshold = 2;
-
- function S (r: real; accuracy: integer): Str255;
-
- var
- theString: Str255;
- Digit: Str255;
- n: integer;
-
- begin
- n := TRUNC(r);
- NumToString(n, theString);
- if (r < 0) and (n = 0) then
- theString := concat('-', theString);
- if r > 0 then
- theString := Concat(' ', theString);
- theString := Concat(theString, '.');
- r := r - n;
- r := abs(r); (* kill sign *)
- while Length(theString) < accuracy do
- begin
- r := r * 10;
- n := TRUNC(r);
- NumToString(n, Digit);
- theString := Concat(theString, Digit);
- r := r - n;
- end;
- S := theString;
- end;
-
- begin
- SetRect(Trect, 0, 20, 520, 380);
- SetTextRect(Trect);
- ShowText;
- TheErr := InitTrigs;
- if theErr <> noErr then
- Writeln('ResErr...');
- count := 0;
- maxdelta := -1;
- sumdelta := 0;
-
- writeln('Beginning Sine-Test');
- for i := 1 to Tries do
- begin
- {$IFC Visual <> TRUE }
- if i mod 50 = 0 then
- write('.');
- {$ENDC}
-
- count := count + 1;
- x := Random;
- y := Random;
- a := x / y;
-
- {$IFC Visual = TRUE }
- write('x : ', S(a, 8));
- write(' sin(x) : ', S(sin(a), 8));
- write(' FSin(x) : ', S(FSin(a), 8));
- {$ENDC }
-
- Delta := abs(sin(a) - FSin(a));
- if Delta > maxDelta then
- begin
- maxDelta := Delta;
- deltapos := a;
- end;
-
-
- sumdelta := sumdelta + delta;
- {$IFC Visual = TRUE }
- write(' || Δ = ', S(delta, 8));
- writeln;
- {$ENDC}
- end;
- writeln;
- writeln('Results of Sine test:');
- writeln('Maximum Δ at ', S(deltapos, 8), ' with ', S(maxdelta, 8));
- writeln;
- writeln('Mean Δ at ', count : 8, ' tries : ', S(sumdelta / count, 8));
-
- writeln;
- writeln;
- writeln;
-
- count := 0;
- maxdelta := -1;
- sumdelta := 0;
-
- writeln('Beginning Cosine-Test');
- for i := 1 to Tries do
- begin
- {$IFC Visual <> TRUE }
- if i mod 50 = 0 then
- write('.');
- {$ENDC}
-
- count := count + 1;
- x := Random;
- y := Random;
- a := x / y;
- {$IFC Visual = TRUE }
- write('x : ', S(a, 8));
- write(' cos(x) : ', S(cos(a), 8));
- write(' FCos(x) : ', S(FCos(a), 8));
- {$ENDC }
- t1 := cos(a);
- t2 := FCos(a);
- Delta := abs(cos(a) - FCos(a));
- if Delta > maxDelta then
- begin
- maxDelta := Delta;
- deltapos := a;
- end;
-
- sumdelta := sumdelta + delta;
- {$IFC Visual = TRUE }
- write(' || Δ = ', S(delta, 8));
- if Delta > 1 then
- begin
- write(' -> Delta > 1! ');
- end;
- writeln;
- {$ENDC}
- end;
- writeln;
- writeln('Results of Cosine test:');
- writeln('Maximum Δ at ', S(deltapos, 8), ' with ', S(maxdelta, 8));
- writeln;
- writeln('Mean Δ at ', count : 8, ' tries : ', S(sumdelta / count, 8));
-
-
- writeln;
- writeln;
- writeln;
-
- count := 0;
- maxdelta := -1;
- sumdelta := 0;
-
- writeln('Beginning Tangens-Test');
- for i := 1 to Tries do
- begin
- {$IFC Visual <> TRUE }
- if i mod 50 = 0 then
- write('.');
- {$ENDC}
- count := count + 1;
- x := Random;
- y := Random;
- a := x / y;
- {$IFC Visual = TRUE }
- write('x : ', S(a, 8));
- write(' tan(x) : ', S(tan(a), 8));
- write(' FTan(x) : ', S(FTan(a), 8));
- write(' [', S(FSin(a) / FCos(a), 8), ']');
- {$ENDC}
- t1 := tan(a);
- t2 := FTan(a);
- Delta := abs(tan(a) - FTan(a));
- if (Delta > maxDelta) and (t1 < treshold) then
- begin
- maxDelta := Delta;
- deltapos := a;
- end;
-
- if abs(t1) < treshold then
- sumdelta := sumdelta + delta
- else
- count := count - 1;
- {$IFC Visual = TRUE }
- write(' || Δ = ', S(delta, 8));
- if abs(t1) > treshold then
- write('*');
-
- if Delta > 1 then
- write('+');
-
- writeln;
- {$ENDC}
- end;
- writeln;
- {$IFC Visual = TRUE }
- writeln(' * Means : Function value was greater than filter treshold. It will not be used ');
- writeln(' for accuracy evaluation');
- writeln(' + Means : Difference between FPU and lookuptable was greater than 1.');
- {$ENDC}
- writeln;
- writeln('Results of Tangens test:');
- writeln('Maximum Δ at ', S(deltapos, 8), ' with ', S(maxdelta, 8));
- writeln;
- writeln('Mean Δ at ', count : 8, ' tries : ', S(sumdelta / count, 8));
- writeln(' (Treshold at ', S(treshold, 8), ')');
-
- writeln('TableResulution (Sine ) was at ', GetSinResolution, ' Values for 2π.');
- writeln('TableResulution (Cosine ) was at ', GetCosResolution, ' Values for 2π.');
- writeln('TableResulution (Tangent) was at ', GetTanResolution, ' Values for 2π.');
- end.